import 'package:dio/dio.dart';
import 'package:ugrownews_flutter/utils/netutil/NetUtil.dart';

class NewsNetUtil extends NetUtil {
  final String _REQUES_TLIST = "/getRequestList";
  final String _LIVE_LIST = "/getLiveList";
  final String _NEWS_LIST = "/listNews";
  final String _NEWS_DETAIL = "/getNewsDetail";
  final String _NEWS_SEARCH = "/searchByKeyWord";

  Future<Response> getRequestList(
      Map<String, String> params, Function(Object, bool) stringCallBack) async {
    try {
      return super.get(_REQUES_TLIST, params, stringCallBack);
    } catch (e) {
      stringCallBack(new NetError(e: e, errorMsg: '未知错误'), false);
      return Future.delayed(Duration(seconds: 0));
    }
  }

  Future<Response> getLivetList(
      Map<String, String> params, Function(Object, bool) stringCallBack) async {
    try {
      return super.get(_LIVE_LIST, params, stringCallBack);
    } catch (e) {
      stringCallBack(new NetError(e: e, errorMsg: '未知错误'), false);
      return Future.delayed(Duration(seconds: 0));
    }
  }

  Future<Response> getNewsList(
      Map<String, String> params, Function(Object, bool) stringCallBack) async {
    try {
      return super.get(_NEWS_LIST, params, stringCallBack);
    } catch (e) {
      stringCallBack(new NetError(e: e, errorMsg: '未知错误'), false);
      return  Future.delayed(Duration(seconds: 0));
    }
  }

  Future<Response> searchNewsList(
      Map<String, String> params, Function(Object, bool) stringCallBack) async {
    try {
      return super.get(_NEWS_SEARCH, params, stringCallBack);
    } catch (e) {
      stringCallBack(new NetError(e: e, errorMsg: '未知错误'), false);
      return  Future.delayed(Duration(seconds: 0));
    }
  }

  Future<Response> getNewsDetail(
      Map<String, String> params, Function(Object, bool) stringCallBack) async {
    try {
      return super.get(_NEWS_DETAIL, params, stringCallBack);
    } catch (e) {
      stringCallBack(new NetError(e: e, errorMsg: '未知错误'), false);
      return Future.delayed(Duration(seconds: 0));
    }
  }
}
